﻿using AutoMapper;
using B.S.Material.Domain.BOM;
using B.S.Material.ErrorCode;
using B.S.Material.Wirth.Api.Applications.Command.FeedDetailsCommand;
using MediatR;
using SqlSugar;

namespace B.S.Material.Wirth.Api.Applications.Handler.FeedDetailsHandler
{
    public class UpateFeedDetailsHandler : IRequestHandler<UpdateFeedDetailsCommand, ApiResult<int>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public UpateFeedDetailsHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        public async Task<ApiResult<int>> Handle(UpdateFeedDetailsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = ApiEnum.修改成功;
            result.MAG = ApiEnum.修改成功.ToString();
            var model = mapper.Map<FeedDetailss>(request);
            var list = db.Queryable<FeedDetailss>().Where(p => p.FeedDetailsId == request.FeedDetailsId);
            if (list.Count() != 0)
            {
                await db.Updateable<FeedDetailss>(model).ExecuteCommandAsync();
            }

            return await Task.FromResult(result);


        }
    }
}
